package com.chuhe.common.domain.vo.resp;
import com.chuhe.common.exception.CommonErrorEnum;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 *
 * @Author: 楚河
 * @Date: 2025-04-25 18:08
 */
@Data
@ApiModel("基础返回体")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ApiResult<T> {
    /**
     * 返回模板
     * @Author: 楚河
     * @Date: 2025-05-12 22:57
     */
    @ApiModelProperty("成功标识true or false")
    private Boolean success;
//    @ApiModelProperty("错误码")
//    private Integer errCode;
//    @ApiModelProperty("错误消息")
//    private String errMsg;
//    @ApiModelProperty("返回消息2")
//    private String message;

   /**
    * 星空聊天室
    * @Author: 楚河
    * @Date: 2025-05-12 22:57
    */
//    @ApiModelProperty("成功状态码")
//    private String status;
    @ApiModelProperty("错误码2")
    private Integer code;
    @ApiModelProperty("返回消息")
    private String info;

    //必存在！！！
    @ApiModelProperty("返回对象")
    private T data;

    protected static final String COOKIE_KEY_TOKEN = "token";

    protected static final String STATUC_SUCCESS = "success";

    protected static final String STATUC_ERROR = "error";
    public static <T> ApiResult<T> success() {
        ApiResult<T> result = new ApiResult<T>();
        result.setData(null);
        result.setSuccess(Boolean.TRUE);
        return result;
    }
//
//    public static <T> ApiResult<T> success(T data) {
//        ApiResult<T> result = new ApiResult<T>();
//        result.setData(data);
//        result.setSuccess(Boolean.TRUE);
//        return result;
//    }
//
//
    public static <T> ApiResult<T> success(T data) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(Boolean.TRUE);
//        result.setStatus(STATUC_SUCCESS);
        result.setCode(CommonErrorEnum.CODE_200.getCode());
        result.setInfo(CommonErrorEnum.CODE_200.getMsg());
        result.setData(data);
        return result;
    }
//
//    public static <T> ApiResult<T> fail(Integer code, String msg) {
//        ApiResult<T> result = new ApiResult<T>();
//        result.setSuccess(Boolean.FALSE);
//        result.setErrCode(code);
//        result.setErrMsg(msg);
//        return result;
//    }

    /**
     * 星空聊天室 适配
     * @Author: 楚河
     * @Date: 2025-05-12 22:31
     */
    public static <T> ApiResult<T> fails(Integer code, String msg) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(Boolean.FALSE);
        result.setCode(code);
        result.setInfo(msg);
        return result;
    }

        public static <T> ApiResult<T> fails(CommonErrorEnum codeEnum) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(Boolean.FALSE);
        result.setInfo(codeEnum.getMsg());
        return result;
    }

//    public static <T> ApiResult<T> fail(ErrorEnum errorEnum) {
//        ApiResult<T> result = new ApiResult<T>();
//        result.setSuccess(Boolean.FALSE);
//        result.setErrCode(errorEnum.getErrorCode());
//        result.setErrMsg(errorEnum.getErrorMsg());
//        return result;
//    }
//
    public boolean isSuccess() {
        return this.success;
    }
}
